<template>
  <dt-modal-edit
    ref="edit"
    title="我司盖章凭证上传"
    :label-width="130"
    :width="500"
    @ok="onOk"></dt-modal-edit>
</template>

<script>
  import uploadCertOpt from '../opt/uploadCert.js'
  import fileMgr from '@/biz/file'
  import initiateMgr from '@/biz/commission/initiate.js'

  export default {
    data() {
      return {
        id: null,
        info: {
          files: null
        }
      }
    },
    mounted() {},
    methods: {
      show(info) {
        this.id = info.commissionId
        initiateMgr.detail({ commissionId: this.id }).then((res) => {
          this.info.files = res.ourVoucherAttaches.map((item) => ({
            name: item.fileName,
            url: item.attachAddress
          }))
          this.$refs.edit.show(uploadCertOpt.options(this.info.files), this.info)
        })
      },
      hide() {
        this.$refs.edit.hide()
      },
      onOk() {
        console.log(this.info.files)
        fileMgr.uploadAttach('OUR_VOUCHER', this.id, this.info.files).then((res) => {
          this.$emit('success', res)
          this.hide()
        })
      }
    }
  }
</script>

<style></style>
